package com.teacold.customdemo.chapter_five;

import android.graphics.drawable.Animatable;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.teacold.customdemo.R;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;

public class FiveActivity extends AppCompatActivity {
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }
    private ImageView five_image,five_search;
    private EditText five_edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_five);
        initView();

        AnimatedVectorDrawableCompat animatedVectorDrawableCompat = AnimatedVectorDrawableCompat.create(this, R.drawable.svg_animated_vector);
        five_image.setImageDrawable(animatedVectorDrawableCompat);
        ((Animatable)five_image.getDrawable()).start();
    }

    private void initView() {
        five_image=findViewById(R.id.five_image);
        five_edit=findViewById(R.id.five_edit);
        five_search=findViewById(R.id.five_search);
        five_search.setFocusable(true);
        five_search.setFocusableInTouchMode(true);
        five_search.requestFocus();
        five_search.requestFocusFromTouch();
        five_edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    AnimatedVectorDrawableCompat animatedVectorDrawableCompat=AnimatedVectorDrawableCompat.create(FiveActivity.this,R.drawable.animated_vecotr_search);
                   five_search.setImageDrawable(animatedVectorDrawableCompat);
                    ((Animatable)five_search.getDrawable()).start();
                }

            }
        });


    }


}
